package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.api.entity.MallCustomerCollect;
import com.alpha.eceasy.mall.service.impl.MallCustomerCollectServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户收藏表 前端控制器
 * </p>
 *
 * @author huangpengfei
 * @since 2024-05-09
 */
@RestController
@RequestMapping("/customer-collect")
@Tag(description = "customer-collect", name = "用户收藏表")
public class MallCustomerCollectController {
    @Resource
    private MallCustomerCollectServiceImpl customerCollectService;

    /**
     * 分页查询
     *
     * @param dto 用户收藏
     * @return 分页结果
     */
    @GetMapping("")
    @Operation(description = "分页查询", summary = "分页查询")
    public R<IPage<MallCustomerCollect>> getPageVO(@RequestParam("pageNum") Integer pageNum,
                                                   @RequestParam("pageSize") Integer pageSize,
                                                   MallCustomerCollect dto) {
        return R.ok(customerCollectService.page(Page.of(pageNum, pageSize), Wrappers.lambdaQuery(dto)));
    }

    /**
     * 通过guid查询用户收藏
     *
     * @param guid guid
     * @return R 返回结果 用户收藏
     */
    @Operation(description = "通过guid查询用户收藏", summary = "通过guid查询用户收藏")
    @GetMapping("/{guid}")
    @Hidden
    public R<MallCustomerCollect> getByGuid(@PathVariable("guid") String guid) {
        return R.ok(customerCollectService.getByGuid(guid));
    }

    /**
     * 新增用户收藏
     *
     * @param dto 用户收藏
     * @return R 返回结果 是否成功
     */
    //@SysLog("新增用户收藏")
    @Operation(description = "新增用户收藏", summary = "新增用户收藏")
    @PostMapping
    public R<Boolean> save(@RequestBody MallCustomerCollect dto) {
        return R.ok(customerCollectService.save(dto));
    }

    /**
     * 通过guid删除用户收藏
     *
     * @param guid guid
     * @return R 返回结果
     */
    //@SysLog("通过id删除商品")
    @Operation(description = "通过guid删除用户收藏", summary = "通过guid删除用户收藏")
    @DeleteMapping("/{guid}")
    public R<Boolean> removeById(@PathVariable String guid) {
        return R.ok(customerCollectService.removeByGuid(guid));
    }

    /**
     * 修改用户收藏
     *
     * @param entity 用户收藏
     * @return R 返回结果 是否成功
     */
    //@SysLog("修改用户收藏")
    @Hidden
    @Operation(description = "通过guid修改用户收藏", summary = "通过guid修改用户收藏")
    @PutMapping
    public R<Boolean> updateById(@RequestBody MallCustomerCollect entity) {
        return R.ok(customerCollectService.updateByGuid(entity));
    }
}
